using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Module.CMS.Library;
using NCS.Module.CMS.Library.Distributions;
using NCS.Library.Utilities;
using NCS.Library;

namespace NCS.Module.CMS.Web.HomePage
{
    public partial class SpecialNewsInHomePage : CMSWebControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //DataTable other = DistributionController.GetDistributedHotNewsContentsbyPortal(ConvertUtility.ToInt32(AppEnv.PortalId()), 1);
            DataTable other = DistributionController.Distributions_GetTinNoiBat(1, AppEnv.PortalId());             

            rptContent.DataSource = other;
            rptContent.DataBind();
        }

        protected void rptContent_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView currow = (DataRowView)e.Item.DataItem;
         
                string title = ConvertUtility.ToString(currow["Content_Headline"]);
                string link = BuildUrlByDistId((int)currow["Distribution_ID"], (int)currow["Distribution_ZoneID"]);
                string summary = ConvertUtility.ToStringWithoutFontBold(currow["Content_Teaser"], 650).TrimEnd();
                string date = ConvertUtility.FormatTimeVn(ConvertUtility.ToDateTime(currow["Distribution_CreateDate"]));
                string ava = ConvertUtility.ToString(currow["SpecialAvatar"]);

                if (string.IsNullOrEmpty(ava) )
                    ava = ConvertUtility.ToString(currow["Content_Avatar"]);
                else
                    ava = MultimediaUtility.GetSpecialAvatar(ava);

                Literal ltt = (Literal)e.Item.FindControl("ltt");
                if (!string.IsNullOrEmpty(ava) && System.IO.File.Exists(Server.MapPath(ava)))
                {
                    string alternate_text = MiscUtility.SafeHtmlToText(ConvertUtility.ToStringWithoutFontBold(currow["Content_AvatarDescription"]));

                    string js_img = "javascript:window.location='" + link + "'";
                    ltt.Text = "<img src='" + ava + "' alt='" + alternate_text + "'  Width='250' onclick=\"" + js_img + "\"/>";                 
                }
                ltt.Text += "<a href='" + link + "'>"+ title + "</a>";
                ltt.Text += "<span class='ngaydang_home'>" + date + "</span>";                
                ltt.Text += summary;
               

            }
        }
    }
}